/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.edu.itschapala.sistemas.septimo.vista;

import mx.edu.itschapala.sistemas.septimo.modelo.Cliente;
import mx.edu.itschapala.sistemas.septimo.modelo.Producto;
import mx.edu.itschapala.sistemas.septimo.vista.enumeracion.TipoVista;
import mx.edu.itschapala.sistemas.septimo.control.ClienteLnLocal;

/**
 *
 * @author Estudiante_2
 */
public class AgregarCliente extends javax.swing.JFrame {

    private ClienteLnLocal clienteControl;
    private TipoVista tipoVentana;
    private Cliente cliente;

    public AgregarCliente(Cliente cliente, ClienteLnLocal clienteControl, TipoVista tipoVentana) {

        initComponents();
        this.clienteControl = clienteControl;
        this.tipoVentana = tipoVentana;
        this.cliente = cliente;
        initComponents();
        switch (tipoVentana) {
            case VENTANA_REGISTRO:
                jLabel5.setText("NUEVO Cliente");
                break;
            case VENTANA_BUSQUEDA:
                jLabel5.setText("BUSCAR POR ID");
                jTextField2.setEditable(false);
                jTextField3.setEditable(false);
                jTextField4.setEditable(false);

                jButton2.setVisible(false);
                break;
            case VENTANA_MODIFICAR:
                jLabel5.setText("MODIFICAR Cliente");
                jTextField1.setEditable(false);
                jTextField1.setText(cliente.getId() + "");
                jTextField2.setText(cliente.getNombre());
                jTextField3.setText(cliente.getTelefono() + "");
                jTextField4.setText(cliente.getSexo());

                break;
            case VENTANA_ELIMINAR:
                jLabel5.setText("ELIMINAR Cliente");
                jTextField2.setEditable(false);
                jTextField3.setEditable(false);
                jTextField4.setEditable(false);

                break;
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jTextField4 = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setLayout(new java.awt.GridLayout(4, 0));

        jLabel1.setText("ID");
        jPanel1.add(jLabel1);
        jPanel1.add(jTextField1);

        jLabel2.setText("Nombre");
        jPanel1.add(jLabel2);
        jPanel1.add(jTextField2);

        jLabel3.setText("Telefono");
        jPanel1.add(jLabel3);
        jPanel1.add(jTextField3);

        jLabel4.setText("Sexo");
        jPanel1.add(jLabel4);
        jPanel1.add(jTextField4);

        jButton1.setText("Aceptar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Cancelar");

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel5.setForeground(new java.awt.Color(255, 0, 0));
        jLabel5.setText("TITULO");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 463, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGroup(layout.createSequentialGroup()
                .addGap(53, 53, 53)
                .addComponent(jButton1)
                .addGap(127, 127, 127)
                .addComponent(jButton2))
            .addGroup(layout.createSequentialGroup()
                .addGap(181, 181, 181)
                .addComponent(jLabel5))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 49, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(32, 32, 32)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addGap(37, 37, 37))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        switch (tipoVentana) {
            case VENTANA_REGISTRO:

                Cliente p = new Cliente();
                p.setId(Integer.parseInt(jTextField1.getText()));
                p.setNombre(jTextField2.getText());
                p.setTelefono(Integer.parseInt(jTextField3.getText()));
                p.setSexo(jTextField4.getText());
                clienteControl.registrar(p);
                jTextField1.setText("");
                jTextField2.setText("");
                jTextField3.setText("");
                jTextField4.setText("");

                break;
            case VENTANA_BUSQUEDA:
                this.dispose();
                break;
            case VENTANA_MODIFICAR:

                p = new Cliente();
                p.setId(Integer.parseInt(jTextField1.getText()));
                p.setNombre(jTextField2.getText());
                p.setTelefono(Integer.parseInt(jTextField3.getText()));
                p.setSexo(jTextField4.getText());
                clienteControl.modificar(p);
                jTextField1.setText("");
                jTextField2.setText("");
                jTextField3.setText("");
                jTextField4.setText("");

                jTextField2.setEditable(false);
                jTextField3.setEditable(false);
                jTextField4.setEditable(false);

                break;
            case VENTANA_ELIMINAR:
                p = new Cliente();
                p.setId(Integer.parseInt(jTextField1.getText()));
                p.setNombre(jTextField2.getText());
                p.setTelefono(Integer.parseInt(jTextField3.getText()));
                p.setSexo(jTextField4.getText());

                clienteControl.eliminar(p);
                jTextField1.setText("");
                jTextField2.setText("");
                jTextField3.setText("");
                jTextField4.setText("");

                jTextField2.setEditable(false);
                jTextField3.setEditable(false);
                jTextField4.setEditable(false);

                break;

        }
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    // End of variables declaration//GEN-END:variables
}
